<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Approval extends MY_Controller {

    //put your code here

    function Approval() {
        parent :: __construct();
        $this->load->helper('url');
        $this->load->library('pagination');
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->load->model('listing_model');
        $this->load->model('management_model');
        $this->load->model('member_model');
        $this->load->model('reviews_model');
        $this->load->model('terms_model');
        $this->load->model('requirement_model');
        $this->load->model('counter_model');
        $this->commoncall->check_admin_login();
    }

//---------Listing Approval ----------------
    function listing() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/approval/listing';
        $config['total_rows'] = $this->counter_model->count_record('listing_master', 1);
        $config['uri_segment'] = '4';
        $config['per_page'] = $per_page;
        $data['listing'] = $this->listing_model->get_listings('CAR', 0, 1, $per_page, $offset);
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_listing_approval', $data);
    }

    //------------- active Listing-----------------
    function active_listing($id=NULL) {
        $sql = "update listing_master set status=51 where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/listing');
    }

    //------------- Active Reviews-----------------
    function reviews() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/approval/reviews';
        $config['total_rows'] = $this->counter_model->count_record('review_master', 1);
        $config['uri_segment'] = '4';
        $config['per_page'] = $per_page;
        $data['review'] = $this->reviews_model->get_reviews(null, $per_page, $offset);
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_review_approval', $data);
    }

//------------- Make Review active by id-----------------
    function active_review($id=NULL) {
        $sql = "update review_master set status=51 where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/reviews');
    }

//--Deleting Review (SUbha)--//
    function delete_review($id=NULL) {
        $sql = "delete from review_master where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/reviews');
    }
    
//------------- Get all Photos-----------------
    function photos() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/approval/reviews';
        $config['total_rows'] = $this->counter_model->count_record('terms', 1);
        $config['uri_segment'] = '4';
        $config['per_page'] = $per_page;
        $data['photos'] = $this->terms_model->get_terms('listing-photo', 0);
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_photo_approval', $data);
    }

// ----- Make Photo Active-------------------------    
    function active_photos($id) {
        $sql = "update terms set status=51 where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/photos');
    }

// ----- Delete Photos-------------------------  
    function delete_photo($id, $description) {
        $path = BASEPATH . './assets/images/data/photo/' . $description;
        unlink($path);
        $this->terms_model->delete_term_by_id($id);
        redirect('admin/approval/photos');
    }

    //--------- Get Videos--------------
    function videos() {

        $data['videos'] = $this->terms_model->get_terms('listing-video', 0);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_video_approval', $data);
    }

//-------- Maake Video active------    
    function active_video($id) {
        $sql = "update terms set status=51 where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/videos');
    }

//------ Delete Video--------------     
    function delete_video($id, $description) {
        $this->terms_model->delete_term_by_id($id);
        redirect('admin/approval/videos');
    }

//----------Get all requirments-------------    
    function get_requirments() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/approval/get_requirments';
        $config['total_rows'] = $this->counter_model->count_record('post_requirement', 1);
        $config['uri_segment'] = '4';
        $config['per_page'] = $per_page;
        $data['requirements'] = $this->requirement_model->get_requirements($type = 'CAR', $status = 1, $per_page, $offset, $mode = 'DESC');
        $this->pagination->initialize($config);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_post_requirement', $data);
    }

//----------Make requirments active-------------
    function active_requirment($id) {
        $sql = "update post_requirement set status=51 where id=$id";
        $this->db->query($sql);
        redirect('admin/approval/get_requirments');
    }

}

?>